package xyz.icxl.kotlion.ext.primitives

import java.io.InputStream
import java.util.*
import kotlin.collections.HashMap

/**
 * 文件描述：输入流扩展
 *
 * 文件创建人：ChenXinLei
 *
 * 文件创建人联系方式：502616659(QQ)
 *
 * 创建时间：2020 年 08月 25 日
 *
 * 文件版本：v1.0
 *
 * 版本描述：创建文件
 */
private val FILE_TYPE_MAP = HashMap<String,String>().apply {
    put("FFD8FF","jpg")
    put("89504E","png")
    put("474946","gif")
    put("49492A","tif")
    put("424D00","bmp")
    put("414331","dwg")
    put("384250","psd")
    put("7B5C72","rtf")
    put("3C3F78","xml")
    put("68746D","html")
    put("44656C","eml")
    put("CFAD12","dbx")
    put("214244","pst")
    put("255044","pdf")
    put("504B03","zip")
    put("526172","rar")
    put("415649","avi")
    put("000001","mpg")
    put("6D6F6F","mov")
}

fun InputStream.getInputStreamType():String{
    val typeArray = ByteArray(3)
    read(typeArray, 0, typeArray.size)
    return FILE_TYPE_MAP[typeArray.toHexString().uppercase(Locale.ROOT)]?:""
}